﻿using AteCapybara;
using ATEDiagnoser;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ATECapybara
{
    public partial class ST_QRCode : Form
    {
        public ST_QRCode()
        {
            InitializeComponent();
        }

        /// <summary>
        /// ST输入的QRCode生成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void st_QRCode_21_TextChanged(object sender, EventArgs e)
        {
            string temp1 = st_QRCode_21.Text.Trim();
            string temp2 = st_QRCode_MAC.Text.Trim();
            if (!string.IsNullOrEmpty(temp1) && !string.IsNullOrEmpty(temp2))
            {
                st_QRCode_result.Text = "[)>06S" + temp1 + "1PATX4LATX23S" + temp2;
            }
            else
            {
                st_QRCode_result.Text = "";
            }
        }
        /// <summary>
        /// 生成ST输入的QRCode图片
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void st_QRCode_result_TextChanged(object sender, EventArgs e)
        {
            //生成QRCode图片
            if (!string.IsNullOrEmpty(st_QRCode_result.Text))
            {
                pictureBox1.Image = GetQRCode.Proudce(st_QRCode_result.Text);
            }
            else
            {
                pictureBox1.Image = null;
            }
            //自动复制
            try
            {
                if (st_autocopy.Checked && !string.IsNullOrEmpty(st_QRCode_result.Text))
                {
                    Clipboard.SetDataObject(st_QRCode_result.Text);
                }
            }
            catch (Exception ee)
            {
                MsgShow.Error(ee.Message);
            }
        }

        /// <summary>
        /// 自动全选
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void common_MouseDown(object sender, MouseEventArgs e)
        {
            var tb = sender as TextBox;
            if (!string.IsNullOrEmpty(tb.Text))
            {
                tb.SelectAll();
            }
        }

        /// <summary>
        /// 输入回车跳到下一个
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void st_QRCode_21_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)//设置监听键为回车
            {
                e.Handled = true; // 防止回车键插入换行符
                //SelectNextControl((Control)sender, true, true, true, true);
                st_QRCode_MAC.Focus();
                st_QRCode_MAC.SelectAll();
            }
        }
        /// <summary>
        /// 输入回车跳到下一个
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void st_QRCode_MAC_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)//设置监听键为回车
            {
                e.Handled = true; 
                st_QRCode_21.Focus();
                st_QRCode_21.SelectAll();
            }
        }
    }
}
